﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OmniKits.Core
{
#pragma warning disable 1591

    using NullGuard;

    public class ActionDisposable
        : DisposableBase
    {
        private Action<bool> _DisposeAction;
        public ActionDisposable([AllowNull]Action<bool> disposeAction)
        {
            _DisposeAction = disposeAction;
        }
        protected override void Dispose(bool disposing)
        {
            if (_DisposeAction != null)
                _DisposeAction(disposing);
        }
    }

    public class EventDisposable
        : DisposableBase
    {
        public event Action<object, EventArgs<bool>> DisposeCalled;
        protected override void Dispose(bool disposing)
        {
            var eventHandler = DisposeCalled;
            if (eventHandler != null)
                eventHandler(this, new EventArgs<bool>(disposing));
        }
    }
}
